package com.sunday.boot3.user.center.rest.api.impl;

import com.sunday.boot3.user.center.controller.UserController;
import com.sunday.boot3.user.center.pojo.dto.user.PageUserReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.RemoveUserReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.SaveUserReqDTO;
import com.sunday.boot3.user.center.pojo.dto.user.UpdateUserReqDTO;
import com.sunday.boot3.user.center.rest.api.UserApi;
import com.sunday.boot3.user.center.rest.vo.user.*;
import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户表 Web impl 层
 * @author: zsy
 * @Create: 2024/09/22 16:24:39
 */
@Slf4j
@RestController
@RequestMapping(UserApi.ACCESS_PATH)
@RequiredArgsConstructor
public class UserApiImpl implements UserApi {

    private final UserController userController;

    /**
     * 获取登录用户信息
     *
     * @param
     * @return {@link RestResponse< GetLoginUserResVO>}
     */
    @Override
    public RestResponse<GetLoginUserResVO> getLoginUser() {
        return RestResponse.convertResultReturn(
                userController.getLoginUser(),
                body -> MapperConvert.map(body, GetLoginUserResVO.class));
    }

    /**
     * @Description: 新增 用户表 数据
     * @Param: [saveUserReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse save(SaveUserReqVO saveUserReqVO) {
        return RestResponse.resultReturn(userController.save(MapperConvert.map(saveUserReqVO, SaveUserReqDTO.class)));
    }

    /**
     * @Description: 删除 用户表 数据
     * @Param: [removeUserReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse remove(RemoveUserReqVO removeUserReqVO) {
        return RestResponse.resultReturn(userController.remove(MapperConvert.map(removeUserReqVO, RemoveUserReqDTO.class)));
    }

    /**
     * @Description: 修改 用户表 数据
     * @Param: [updateUserReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse update(UpdateUserReqVO updateUserReqVO) {
        return RestResponse.resultReturn(userController.update(MapperConvert.map(updateUserReqVO, UpdateUserReqDTO.class)));
    }

    /**
     * @Description: 获取 用户表 分页列表数据
     * @Param: [pageUserReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.fegin.FeginPageResultVO < com.sunday.boot3.user.center.rest.vo.user.PageUserResVO>>
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    public RestResponse<PageVO<PageUserResVO>> page(PageUserReqVO pageUserReqVO) {
        return RestResponse.convertResultReturn(
                userController.page(MapperConvert.map(pageUserReqVO, PageUserReqDTO.class)),
                body -> PageVO.of(body, PageUserResVO.class));
    }

}